package com.bwie.controller;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @ClassName TestMain
 * @Description TODO
 * @Author {涛}
 * @Date 2024/11/28 13:57
 * @Version 1.0
 */
public class TestMain {


    public static void main(String[] args) {

        ArrayList<String> list1 = new ArrayList<>();
        list1.add("张无忌");
        list1.add("周芷若");
        list1.add("赵敏");
        list1.add("张强");
        list1.add("张三丰");


//        list1.stream().filter(name->name.startsWith("张")).filter(name->name.length()==3).forEach(name-> System.out.println(name));
//        System.out.println("--------------");
//        list1.stream().filter(name->name.endsWith("强")).forEach(name-> System.out.println(name));

//
//        ArrayList<String> list = new ArrayList<>();
//
//        Collections.addAll(list, "张无忌-15", "周芷若-14","赵敏-13","张强-20", "张三丰-100", "张翠山-40", "张良-35", "王二麻子-3");
//
//        list.stream().map(s->Integer.parseInt(s.split("-")[1])).forEach(s->System.out.println(s));
//        list.stream().map(s->s.split("-")[0]).forEach(s->System.out.println(s));


        //ArrayList<String> list = new ArrayList<>();
        //Collections.addAll(list, "张无忌-男-15","周芷若-女-14","赵敏-女-13","张强-男-20","张翠山-男-40","张良-男-35","王二麻子-男-37","谢广坤-男-41","张三丰_男-100");

//        list.stream().filter(s-> "男".equals( s.split("-")[1])).forEach(s-> System.out.println(s));


//        Map<String, String> collect = list.stream().filter(s -> "男".equals(s.split("-")[1]))
//                .collect(Collectors.toMap(
//                        s -> s.split("-")[0],
//                        s -> s.split("-")[2]
//                ));
//
//        System.out.println(collect);

        ArrayList<Integer> list = new ArrayList<>();
        Collections.addAll(list, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10);

        List<Integer> collect = list.stream().filter(s -> s % 2 == 0).collect(Collectors.toList());
        System.out.println(collect);

        System.out.println("--------------------------");
        ArrayList<String> list2 = new ArrayList<>();
        Collections.addAll(list2, "zhangsan,23", "lisi,24", "wangwu,25");
        Map<String, String> map = list2.stream().
                filter(s -> Integer.parseInt(s.split(",")[1]) >= 24)
                .collect(Collectors.toMap(
                        s -> s.split(",")[0],
                        s -> s.split(",")[1]
                ));

        System.out.println(map);

    }

}


